"""模拟管理员的类"""

class User:
	"""用户信息概要"""

	def __init__(self, first, last, **user_info):
		"""初始化用户属性值"""
		self.first_name = first
		self.last_name = last
		self.login_attempts = 0
		self.storage = {}				# 设置storage属性
		for k, v in user_info.items():	# //遍历赋值 **kw相当于dict，遍历取key，value
			self.storage[k] = self.storage.get(k, v) 	
			# 方法get()的第一个参数用于指定键，是必不可少的；第二个参数为指定的键不存在时要返回的值，是可选的
			# 当该方法前接空字典时，与for语句构成字典添加键值对方法，上述语句在self.storage属性列表中添加传入的任意参数对（**user_info）作为键值对
		# print(self.storage)	# 用于测试上述方法返回值是否正确
			# setattr(self, k, v)			# setattr() 设置新的属性	setattr(self, 'address', 'asia') 等价于  self.address = 'asia'

	def describe_user(self):
		"""打印用户信息摘要"""
		print(f"Your name:{self.first_name.title()} {self.last_name.title()}.")
		k_list = []
		for k in self.storage.keys():
			k_list.append(k)
		if len(k_list) > 0:
			print("Please check your extra information")
			for key in k_list:
				print(f"\t{key}: {self.storage[key]}")

	def greet_user(self):
		"""向用户发出个性化问候"""
		print(f"Welcome Your, {self.first_name.title()} {self.last_name.title()}!")

	def increment_login_attempts(self):
		"""递增登录用户人数"""
		self.login_attempts += 1

	def reset_login_attempts(self):
		"""重置登录用户人数"""
		self.login_attempts = 0

class Privileges:
	"""简单模拟权限管理"""

	def __init__(self):
		"""初始化privileges的属性"""
		self.privileges = ['can add post', 'can delete post', 'can ban user']

	def show_privileges(self):
		"""显示管理员权限"""
		print("\nYou have the following permissions:")
		for privilege in self.privileges:
			print(privilege)

class Admin(User):
	"""简单模拟管理员"""

	def __init__(self, first, last, **user_info):
		"""
		初始化父类User的属性。
		再初始化Admin特有的属性。
		"""
		super().__init__(first, last, **user_info)
		self.privileges = Privileges()
		